Skip to content

Add optional error code for legacy type comments#20616

Open
cdce8p wants to merge 3 commits intopython:masterfrom
cdce8p:deprecate-type-comments
Open

Add optional error code for legacy type comments#20616
cdce8p wants to merge 3 commits intopython:masterfrom
cdce8p:deprecate-type-comments

Conversation

@cdce8p
Copy link
Copy Markdown
Collaborator

@cdce8p cdce8p commented Jan 18, 2026

Ref #12947

@cdce8p cdce8p marked this pull request as draft January 18, 2026 17:52
@github-actions

This comment has been minimized.

@emmatyping
Copy link
Copy Markdown
Member

I think if we are going to deprecate type comments we will absolutely need to provide a switch to let folks silence this message. Based on the primer output, it seems (expectedly) that the usage of type comments are pervasive in some code bases. These code bases should be allowed to ignore this deprecation for now. I also think if we are going to deprecate type comments loudly we should link from the deprecation message to a page in the documentation about how to migrate a codebase using type comments to annotations automatically (or at least, mostly automatically). This page should mention things like the libcst codemod https://libcst.readthedocs.io/en/latest/codemods.html#libcst.codemod.visitors.ApplyTypeAnnotationsVisitor

@JukkaL
Copy link
Copy Markdown
Collaborator

JukkaL commented Jan 21, 2026

We should probably start with a new opt-in error code about type comments and explaining that we are planning to (soft) deprecate type comments eventually.

I'm working on a new parser for mypy and it doesn't yet fully support type comments, but it may be worth it to continue to support them still in the future, if many old type comments are still around. I think I can add full support for type comments to the new parser, it's just some extra work.

We might require some flag to even parse type comments at some point, but this would be a backward compatibility break.

@hauntsaninja
Copy link
Copy Markdown
Collaborator

hauntsaninja commented Feb 2, 2026

I am fine with opt-in errors, but strongly against on-by-default errors for this. I think there are ways we can spend our churn budget that are better for users.

Happy to help with parser work (including adding support for type comments)!

@JukkaL
Copy link
Copy Markdown
Collaborator

JukkaL commented Feb 3, 2026

The new parser is being developed here: https://github.com/mypyc/ast_serialize

@cdce8p cdce8p force-pushed the deprecate-type-comments branch from b0fa476 to 45811f6 Compare February 24, 2026 12:16
@cdce8p cdce8p changed the title Deprecate type comments Add optional error code for legacy type comments Feb 24, 2026
@cdce8p cdce8p marked this pull request as ready for review February 24, 2026 12:17
@cdce8p cdce8p force-pushed the deprecate-type-comments branch from 45811f6 to bb88dca Compare February 24, 2026 12:21
@github-actions

This comment has been minimized.

@cdce8p cdce8p force-pushed the deprecate-type-comments branch from bb88dca to f33c922 Compare February 24, 2026 12:47
@github-actions

This comment has been minimized.

@github-actions
Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants